package org.yogthos;

import org.anddev.andengine.engine.handler.physics.PhysicsHandler;
import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;

public class Fish extends AnimatedSprite {

	private final PhysicsHandler physicsHandler;
	private int cameraWidth;
	public int value = 10;
	
	public Fish(int cameraWidth, float pX, float pY, float xv, TiledTextureRegion pTextureRegion) {
		super(pX, pY, pTextureRegion);
		this.physicsHandler = new PhysicsHandler(this);
		this.registerUpdateHandler(this.physicsHandler);
		this.physicsHandler.setVelocity(xv, 0);
		this.cameraWidth = cameraWidth;
	}

	@Override
	protected void onManagedUpdate(final float pSecondsElapsed) {
		float xv = this.physicsHandler.getVelocityX();

		//sine movement
		//banner.style.top = 50 * Math.sin( start ) + 80 + 'px';
		//start += 0.05;
		
		if (this.mX + this.getWidth() > cameraWidth && xv > 0 || this.mX < this.getWidth() && xv < 0)
			this.physicsHandler.setVelocityX(-xv);
		
		super.onManagedUpdate(pSecondsElapsed);
	}
}
